<!DOCTYPE html >
<html>
<head>
<meta charset="UTF-8">
<title>css格式化工具</title>
<link rel="shortcut icon" href="/WX-PLATFORM/resources/images/favicon2.ico">
<style type="text/css">
	html,body,form,fieldset,textarea { height:97%; margin:0; padding:0; border:0; font-size:10pt; background:#F0F1F0; }
	form { margin:0 1%; overflow:hidden; }
	legend { font-family: 微软雅黑;color: #FF9800;font-size: 18px;line-height:3em; font-weight:bolder; }
	button { outline:none;float:left; margin:1% 1% 0 0; cursor:pointer;  border:1px solid #FF9800;background:#fff;color:#FF9800;padding:5px 10px;font-family:微软雅黑;font-size:16px;}
	textarea {padding-top: 10px;font-size: 16px;outline: none;text-indent:1em;width:80%; height:20em; display:block; background:#fff;border:1px solid #FF9800; }
	.footer{ text-align:center;padding:20px 0;font-size:16px;}
</style>
</head><body>
	<form action="" onsubmit="return false">
		<fieldset>
			<legend>css格式化工具</legend>
			<textarea placeholder="请输入你的css代码" name="" rows="" cols="" id="codeText"></textarea>
			<button type="button" onclick="$('codeText').value=code.A();">压缩代码</button>
			<button type="button" onclick="$('codeText').value=code.B();">格式(多行)</button>
			<button type="button" onclick="$('codeText').value=code.C();">格式(单行)</button>
			<button type="button" onclick="$('codeText').value=code.Z();">还原代码</button>
		</fieldset>
	</form>
	<div class="footer" style="color:#C7C4C4;">@Tony - 陕西西安高新区...</div> 
<script type="text/javascript">
function $(id){return document.getElementById(id);}
function codeZip(obj){
	this.S=function(){
		var code=obj.value;
		if(!this.codeZ||this.codeZ=="")this.codeZ=code;
		code=code.replace(/(\n|\t|\s)*/ig,'$1');
		code=code.replace(/\n|\t|\s(\{|\}|\,|\:|\;)/ig,'$1');
		code=code.replace(/(\{|\}|\,|\:|\;)\s/ig,'$1');
		return code;
	}
	this.A=function(){
		var code=this.S();
		return code;
	} 
	this.B=function(){
		var code=this.S();
		code=code.replace(/(\{)/ig,' $1');
		code=code.replace(/(\{|\;)/ig,'$1\n\t');
		code=code.replace(/\t*(\})/ig,'$1\n');
		code=code.replace(/(\*\/)/ig,'$1\n');
		return code;
	}
	this.C=function(){
		var code=this.S();
		code=code.replace(/(\})/ig,'$1\n');
		code=code.replace(/(\*\/)/ig,'$1\n');
		return code;
	} 
	this.Z=function(){
		return (this.codeZ)?this.codeZ:obj.value;
	}
	var my=this;
	obj.onkeydown=function(){
		my.codeZ="";	
	}
}
var code=new codeZip($('codeText'));
</script>

</body></html>